package com.scy.edu.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author 司晨雨
 * @date 2020/6/28 21:07
 * @description
 */
public class Response {

    private OutputStream outputStream;

    public Response() {
    }

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void outPut(String content) throws IOException {
        outputStream.write(content.getBytes());
    }


    public void outputHtml(String path) throws IOException {
        String absoluteResourcePth = StaticResourceUtil.getAbsolutePath(path);

        File file = new File(absoluteResourcePth);
        if(file.exists() && file.isFile()){
            //读取静态资源文件，输出静态资源
            StaticResourceUtil.outputStaticResource(new FileInputStream(file),outputStream);
        }else{
            //输出404
            outPut(HttpProtocolUtil.getHttpHeader404());
        }

    }

}
